//
//  NSString+BMLDM5.m
//  24 Homework MD5 SHA-1 DES
//
//  Created by GivenBmli on 16/8/17.
//  Copyright © 2016年 GivenBmli. All rights reserved.
//

#import "NSString+BMLDM5.h"
#import <CommonCrypto/CommonCrypto.h>
@implementation NSString (BMLDM5)
- (NSString *)stringWith32DM5 {
    const char *cSting = [self UTF8String];
    CC_LONG leght = (CC_LONG)strlen(cSting);
    unsigned char dyer [CC_MD5_DIGEST_LENGTH];
    
    CC_MD5(cSting, leght, dyer);
    NSMutableString *fingSting = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH *2 ];
    for (int i = 0; i< CC_MD5_DIGEST_LENGTH; i++) {
        [fingSting appendFormat:@"%02x",dyer[i]];
    }
    return fingSting;
}
- (NSString *)stringWith32DM5Lower {
    
    return [[self stringWith32DM5]lowercaseString];
}
- (NSString *)stringWith32DM5Upper {
    return [[self stringWith32DM5]uppercaseString];
}

- (NSString *)stringWith16DM5 {
//    NSString *md5Sting32Bit = [self stingWith32BitMD5];
//    NSString *md5Sting16Bit = [md5Sting32Bit substringToIndex:md5Sting32Bit.length - 8];
//    md5Sting16Bit = [md5Sting16Bit substringFromIndex:8];
//    return md5Sting16Bit;

    NSString *md32StingBit = [self stringWith32DM5];
    NSString *md16Sting = [md32StingBit substringToIndex:md32StingBit.length - 8];
    md16Sting = [md16Sting substringFromIndex:8];
    return md16Sting;
}
- (NSString *)stringWith16DM5Lower {
    return [[self stringWith16DM5]lowercaseString];
}
- (NSString *)stringWith16DM5Upper {
    return [[self stringWith16DM5]uppercaseString];
}


@end
